package com.medicine.sys.controller;

import com.medicine.common.base.ResponseData;
import com.medicine.sys.entity.Role;
import com.medicine.sys.entity.User;
import com.medicine.sys.param.RoleParam;
import com.medicine.sys.param.UserParam;
import com.medicine.sys.service.RoleService;
import com.medicine.sys.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(description = "角色管理")
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @ApiOperation(value="角色列表查询")
    @GetMapping("")
    public ResponseData pageList(RoleParam roleParam){
        return ResponseData.success("查询成功！",roleService.selectPageList(roleParam));
    }

    @ApiOperation(value="查询全部角色")
    @GetMapping("/list")
    public ResponseData list(){
        return ResponseData.success("查询成功！",roleService.selectList());
    }

    @ApiOperation(value="角色新增")
    @PostMapping
    public ResponseData install(Role role) throws Exception {
        roleService.install(role);
        return ResponseData.success("新增成功！");
    }


    @ApiOperation(value="角色修改")
    @PutMapping
    public ResponseData update(Role role) throws Exception {
        roleService.install(role);
        return ResponseData.success("修改成功！");
    }

    @ApiOperation(value="角色详情查询")
    @GetMapping("/{id}")
    public ResponseData list(@PathVariable String id){
        return ResponseData.success("查询成功！",roleService.getId(id));
    }
}
